import java.util.Arrays;


//右旋字符串，是翻转单词的一个应用，先两个区间分别进行倒置，再对整体进行倒置，当然也可以先整体再局部
public class rightRotationString {
    public void reverse(char[] st,int start,int end){//翻转字符串，k
        int k = (end - start+1)/2;
        while (k>0){
            char temp = st[start];
            st[start] = st[end];
            st[end] = temp;
            k--;
            start++;
            end--;
        }
    }
    public void rotation(char[] cs,int index){//index表示右旋位数
        reverse(cs,0,cs.length-index-1);
        System.out.println(Arrays.toString(cs));
        reverse(cs,cs.length-index,cs.length-1);
        System.out.println(Arrays.toString(cs));
        reverse(cs,0,cs.length-1);
    }
    public static void main(String[] args) {
        String s = "abcdefg";
        char[] cs = s.toCharArray();
        var main = new rightRotationString();
        main.rotation(cs,3);
        System.out.println(Arrays.toString(cs));
    }
}
